package com.rollawizards.input 
{
    import flash.display.DisplayObject;
    import flash.events.EventDispatcher;
    import flash.events.MouseEvent;

    public class Mouse extends EventDispatcher
    {
        private var m_MouseDown:Boolean = false;
        private var m_MouseX:Number = 0;
        private var m_MouseY:Number = 0;
        
        public function Mouse(displayObject:DisplayObject) 
        {
            displayObject.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
            displayObject.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
            displayObject.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
        }
        
        public function get down():Boolean
        {
            return m_MouseDown;
        }

        public function get x():Number
        {
            return m_MouseX;
        }

        public function get y():Number
        {
            return m_MouseY;
        }

        private function onMouseDown(e:MouseEvent):void
        {
            m_MouseDown = true;
            dispatchEvent(new InputEvent(InputEvent.MOUSE));
        }

        private function onMouseUp(e:MouseEvent):void
        {
            m_MouseDown = false;
            dispatchEvent(new InputEvent(InputEvent.MOUSE));
        }

        private function onMouseMove(e:MouseEvent):void
        {
            m_MouseX = e.stageX;
            m_MouseY = e.stageY;
            dispatchEvent(new InputEvent(InputEvent.MOUSEMOVE));
        }
    }
}